package com.color.admin.common.core.result;

/**
 * @author HaiQiu
 * @date 2021/11/18
 * 返回码枚举类
 */
public enum ResultCode {
    /**
     * 常用类型枚举
     */
    INVALID(420,"无效数据"),
    NOT_FIND(404,"资源不存在"),
    AUTH_EXITS(402,"权限菜单已失效，请重新登录"),
    TOKEN_INVALID(402,"令牌过期或失效"),
    NOT_LOGIN(401,"账号未登录"),
    NOT_AUTH(403,"账号无权限"),
    LOGIN_ERROR(510,"你已经连续多次登录失败，已冻结15分钟"),
    FORCE_LOGIN_OUT(512,"已注销"),
    OK(200,"成功"),
    FAIL(500,"失败");

    int code;
    String msg;

    ResultCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    ResultCode() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "ResultCode{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }

    public String getMsg(Integer code){
        for (ResultCode resultCode : values()){
            if (resultCode.code == code){
                return resultCode.msg;
            }
        }
        return null;
    }
}
